﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<script>
    $(document).ready(function () {
        function getPlaceFromFlickr(lat, lon, callback) {
            // the YQL statement
            var yql = 'select * from flickr.places where lat=' + lat + ' and lon=' + lon;

            // assembling the YQL webservice API
            var url = 'http://query.yahooapis.com/v1/public/yql?q=' +
              encodeURIComponent(yql) + '&format=json&diagnostics=' +
              'false&callback=' + callback;

            // create a new script node and add it to the document
            var s = document.createElement('script');
            s.setAttribute('src', url);
            document.getElementsByTagName('head')[0].appendChild(s);
        };

        // callback in case there is a place found
        function output(o) {
            if (typeof (o.query.results.places.place) != 'undefined') {
                alert(o.query.results.places.place.name);
            }
        }

        
        // if the browser supports the w3c geo api
        if (navigator.geolocation) {
            // get the current position
            navigator.geolocation.getCurrentPosition(
                          function (position) {
                              var lat = position.coords.latitude;
                              var lon = position.coords.longitude;
                              $("#info").html("lat: " + lat + " lon:" + lon);
                              // call the function with my current lat/lon
                              getPlaceFromFlickr(lat,lon, 'output');
                          },
                          function (error) {
                              alert('ouch');
                          });
        }
    });
</script>